package com.niguang.work.labour.common.file;

import com.alibaba.fastjson.JSONObject;
import com.niguang.work.labour.common.file.servie.FileService;
import com.niguang.work.labour.common.pojo.Result;
import lombok.NonNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/file/")
public class FileController {

    @Resource
    private FileService fileService;

    /**
     * 文件上传，不用token
     *
     * @param file
     * @return
     */
    @PostMapping("upload")
    public Result uploadFile(@NonNull @RequestParam(value = "file") MultipartFile[] file) {
        List<JSONObject> returnFile = fileService.uploadFile(file);
        return returnFile == null ? Result.failed() : Result.success(returnFile);
    }
}
